/** \file    ActivePixelsBitmap.cpp
  * \brief   Returns bitmap of pixels of active segments.
  * \date    2001 - 2003
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/segm/src/ActivePixelsBitmap.cpp,v 1.1 2004/05/20 09:11:46 cscom1r4 Exp $
  */

#include "segm/Segmentation.h"
#include "imglib/bitmap.h"

void Segmentation::activePixelsBitmap(img::bitmap & bmp) const
{
	int w = width();
	int h = height();
	bmp.resize(w, h);
	int x,y;
	for( y = 0; y != h; ++y ) {
		for( x = 0; x != w; ++x ) {
			const Segment *g = pSegment(x,y);
			bmp.at(x,y) = g && g->active;
		}
	}
}

void Segmentation::mixedGranulateMask(img::bitmap &bmp, double coveringRatio) const
{
	assert(coveringRatio >= 0 && coveringRatio <= 0.5);

	DoubleArr cover;
	covering(bmp, cover);

	int w = width();
	int h = height();
	bmp.resize(w, h);
	int x,y;
	for( y = 0; y != h; ++y ) {
		for( x = 0; x != w; ++x ) {
			int ig = segmentIndex(x,y);
			if (ig == -1)
				continue;
			if (cover[ig] <= coveringRatio)
				bmp.at(x,y) = false;
			else if (cover[ig] >= 1-coveringRatio)
				bmp.at(x,y) = true;
		}
	}
}
